// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import routes from './router'
import VueRouter from 'vue-router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// import './assets/icons-map/iconfont.css'
// import './assets/icons-nav/iconfont.css'
import store from './store'
import echarts from 'echarts'

Vue.use(ElementUI)
Vue.use(VueRouter)
Vue.prototype.$echarts = echarts 

Vue.config.productionTip = false

const router = new VueRouter({
  //取消#后缀
  mode: 'hash',
  routes
})

router.beforeEach((to, from, next) => {
  // console.log(to.matched);
  if (to.path == '/') {
    next('/home');
    sessionStorage.removeItem('islogin');
  }else{
    next();
  }
  if (to.matched.some(m => m.meta.auth)) {
    var login =sessionStorage.getItem('islogin');
    if (login==undefined &&store.state.Auth.islogin != 1) {
      // 未登录则跳转到登陆界面，query:{ Rurl: to.fullPath}表示把当前路由信息传递过去方便登录后跳转回来；
      next({
        path: '/home',
        query: {
          Rurl: to.fullPath
        }
      })
    } else {
      next();
    }
  }

})


/* eslint-disable no-new */
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
